<?php
// Tampon qui intercepte tous les outputs jusqu'à ob_end_flush (automatique), en zippant le contenu si possible
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip')) ob_start('ob_gzhandler');
else ob_start();

session_start();

// session de l'utilisateur
if (!isset($_SESSION['is_connect'])) {
    $_SESSION['is_connect'] = false;
}

require_once('lib/constants.php');
error_reporting(E_ALL | E_STRICT);

// Définition du fuseau horaire
date_default_timezone_set(TIMEZONE);

require_once('lib/utils.php');
require_once('lib/mysql.php');
require_once('lib/member.php');

// connexion à la BDD
sql_connect();

// connexion/deconnexion de l'utilisateur
if (!$_SESSION['is_connect']) {
	// connexion depuis le formulaire
	if (isset($_POST['submit-connection'])) {
		$email = clean_str($_POST['email']);
		$password = crypt_password($_POST['password']);

		if (member_connect($email, $password)) {
			if (isset($_POST['remember'])) {
				// enregistrement de l'email et du password chiffré dans un cookie
				setcookie('adr-login', $email, COOKIE_EXPIRE);
				setcookie('adr-password', $password, COOKIE_EXPIRE);
			}
		}
	}
	// sinon, connexion depuis le cookie
	else if (isset($_COOKIE['adr-login']) && isset($_COOKIE['adr-password'])) {
		$login = clean_str($_COOKIE['adr-login']);
		$password = clean_str($_COOKIE['adr-password']);
		member_connect($login, $password);
	}
}
else if (isset($_GET['deconnexion'])) {
	// demande de déconnexion
	session_destroy();
	$_SESSION['is_connect'] = false;

	// suppression des cookies
	setcookie('adr-login', 0, COOKIE_UNSET);
	setcookie('adr-password', 0, COOKIE_UNSET);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr">
<head>
	<title>
	<?php
	$page = isset($_GET['p']) ? $_GET['p'] : 'club';
	if(isset($_GET['content'])) {
		$rubrique = $page;
		$rub_tit = $_GET['content'];
		echo generate_title(TITLE, $page, $rub_tit);
	}
	else {
		$rubrique = isset($_GET['r']) ? $_GET['r'] : $page;
		echo generate_title(TITLE, $page, $rubrique);
	}
	?>
	</title>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="author" content="Alexandre Bodelot, Julien Paroche" />
	<meta name="description" content="Site internet de l'association Adrénaline, club d'escalade de Garches et Saint-Cloud. Informations et inscriptions disponibles en ligne." />
	<meta name="keywords" content="adrénaline, adrenaline, escalade, club, garches, garche, saint cloud, saint-cloud, grimper, grimpe association, sport, hauts-de-seine, hauts de seine, 92, fontainebleau, rocher, escalader, mur, salle, paris, île de france, pan, prise, bloc, climbing, voie, varape, cœur de seine, sportif, sportive, jeune, remise en forme, centre sportif, activité, enfant, adulte, stage" />
	<meta name="reply-to" content="contact@adrenaline-escalade.com" />

	<!-- css -->
	<link rel="stylesheet" media="screen" type="text/css" href="design/public.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="design/commun.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="design/jquery.css" />
	<link rel="stylesheet" media="screen" type="text/css" href="design/slickmap.css" />
	<!--[if lte IE 7]>
	<link rel="stylesheet" media="screen" type="text/css" href="design/ie.css"  />
	<![endif]-->

	<!-- jquery libs - web -->
	<!--<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js" type="text/javascript"></script>
	<script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.2/jquery-ui.min.js" type="text/javascript"></script>-->

	<!-- jquery libs - loc -->
	<script src="javascript/jquery/jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery-ui-1.8.2.custom.min.js" type="text/javascript"></script>
	<script src="javascript/jquery/jquery.numeric.pack.js" type="text/javascript"></script>
	<script src="javascript/jquery/selectivizr-min.js" type="text/javascript"></script>

	<!-- javascript -->
	<script src="javascript/utils.js" type="text/javascript"></script>
	<script src="javascript/toolbar.js" type="text/javascript"></script>

	<!-- rss feed links -->
	<link rel="alternate" type="application/rss+xml" href="<?php echo FLUX_RSS ?>" title="Adrénaline - Actualités" />
	<?php if ($_SESSION['is_connect']) { ?>
		<link rel="alternate" type="application/rss+xml" href="<?php echo FLUX_RSS_FORUM ?>" title="Adrénaline - Forum" />
	<?php } ?>

	<!-- website mini-icon -->
	<link rel="icon" href="images/adrenaline-icon.png" type="image/png" />

	<!-- google webmaster tools -->
	<meta name="verify-v1" content="d9qzZm5RnrA035Aymrsmqa9/Fd1dTp3bQG8OQ8NBlvc=" />

	<!-- Google Analytics
	<script type="text/javascript" src="javascript/google-analytics.js"></script> -->
</head>

<body>
	<?php
	// $page/$rubrique dans le <title>

	echo '<div id="global">';
	require_once('includes/public_header.php');				// <div id="public_header">

	include_once('includes/public_toolbar.php');			// <div id="public_toolbar">

	echo '<div id="middle">';
		require_once('includes/public_menu_left.php');		// <div id="public_menu_left">
		echo '<div id="public_content" class="colonne">';

		$path = remove_updir('pages/'.$page.'/'.$rubrique.'.php');
		if (file_exists($path)) {
			require_once($path);
		}
		else {
			echo '<p class="error">La page demandée n\'existe pas</p>';
		}
		echo '</div>';
	echo '</div>';

	require_once('includes/public_footer.php');				// <div id="public_footer">

	echo '</div>';
	?>
</body>
</html>
